<?php
/*
 * Unit_model
 * An easier way to construct your unit testing
 * and pass it to a really nice looking page.
 *
 * @author sjlu
 */
class Noticiamodel extends CI_Model {
	
   	function __construct()
   	{
      parent::__construct();
  	}
   
	function acesso()
    {   	
    	$this->db->select('senha');
    	$this->db->where('idsenha', 1);
    	$query = $this->db->get('senha');
        return $query->row()->senha;
    }
    
    function inserir_noticia($assunto, $noticia)
    {
    	$data = array(
               'assunto' => $assunto,
               'noticia' => $noticia
            );
   
        $this->db->insert('noticias', $data);
        
        return TRUE;
    }
    
	function get_where($id)
		{
    		$this->db->where('idnoticias', $id);
    		$query = $this->db->get('noticias');
    		
    		$conteudo = $query->row();
    		
    		return $conteudo;
		}

	function atualizar_noticia($id, $assunto, $noticia){
		
		$data = array(
               'assunto' => $assunto,
               'noticia' => $noticia
            );

		$this->db->where('idnoticias', $id);
		$this->db->update('noticias', $data);
		
		return TRUE;
	}
	
	function atualizar_publicidade(){
		
		$this->db->select('*');
		$this->db->from('noticias');
		$this->db->order_by('idnoticias', 'desc'); 
		$this->db->limit(5);
		$query = $this->db->get();

			$teste = $query->result();
		
			$data['val'] = 0;
			$data['valor_previous'] = 0;
			$data['pagina_principal'] = 0;
			$data['result'] = 1;
			$data['quantidade'] = count($query->result());
			$data['next'] = false;
			$data['previous'] = false; 
			$data['exibe'] = $query->result();
		
    		$this->load->view('frontpage', $data);
	}
	
	function atualizar_next($next, $pagina_principal){
		
		$this->db->select('*');
		$this->db->from('noticias');
		$this->db->where('idnoticias < ', $next);
		$this->db->order_by('idnoticias', 'desc'); 
		$this->db->limit(5);
		$query = $this->db->get();
				
			$data['val'] = 0;
			$data['valor_previous'] = 0;
			$data['pagina_principal'] = $pagina_principal;
			$data['next'] = true;
			$data['previous'] = false;
			$data['quantidade'] = count($query->result());
			$data['result'] = 1;
			$data['exibe'] = $query->result();
		
    		$this->load->view('frontpage', $data);
	}
	
	function atualizar_previous($previous, $limite, $pagina_principal){
		
		$this->db->select('*');
		$this->db->from('noticias');
		$this->db->where('idnoticias > ', $previous);
		$this->db->order_by('idnoticias', 'asc');
		$this->db->limit(5);
		$query = $this->db->get();
		
		$this->db->select('*');
		$this->db->from('noticias');
		$this->db->where('idnoticias > ', $limite);
		$result = $this->db->get();
		
			
			$data['valor_previous'] = 0;
			$data['val'] = 0;
			$data['pagina_principal'] = $pagina_principal;
			$data['next'] = false;
			$data['previous'] = true;
			$data['quantidade'] = count($query->result());
			$data['result'] = $result->result();
			$data['exibe'] = $query->result();
		
    		$this->load->view('frontpage', $data);
	}
	
	function atualizar_deletar($id){
		
		$this->db->where('idnoticias', $id);
		$this->db->delete('noticias');
		
		return TRUE;
	}
	

}
